import 'package:easy_refresh/easy_refresh.dart';
import 'package:get/get.dart';
import 'package:infinite_scroll_pagination/infinite_scroll_pagination.dart';
import 'package:pornhub_app/assets/assets.dart';
import 'package:pornhub_app/components/base_refresh/base_refresh_page_counter.dart';
import 'package:pornhub_app/http/api/api.dart';
import 'package:pornhub_app/model/mine/record_model.dart';
import 'package:pornhub_app/utils/logger.dart';

class RechargeRecordPageController extends GetxController
    with BaseRefreshPageCounter {
  int type = 2;

  EasyRefreshController refreshController = EasyRefreshController();
  final PagingController<int, RecordModel> pagingControllers =
      PagingController(firstPageKey: 1);

  @override
  void onInit() {
    type = Get.arguments['type'] ?? 2;
    super.onInit();
  }

  onRefresh() async {
    geRechargeRecordList(isRefresh: true);
  }

  onLoad() async {
    geRechargeRecordList(isRefresh: false);
  }

  geRechargeRecordList({required bool isRefresh}) async {
    if (isRefresh) {
      resetPage();
      pagingControllers.refresh();
    } else {
      incPage();
    }
    final response = await Api.geRechargeRecordList(
      tranType: type,
      page: page,
    );
    if (response.isNotEmpty) {
      pagingControllers.appendPage(response, page);
    } else {
      pagingControllers.appendLastPage([]);
    }
  }

  getPayType(int payType) {
    switch (payType) {
      case 1:
        return Assets.iconAli;
      case 2:
        return Assets.iconWx;
      case 3:
        return Assets.iconYsf;
      default:
        return Assets.iconPayBalance;
    }
  }

  String getTranType(int tranType) {
    switch (tranType) {
      case 1:
        return '充值';
      case 2:
        return '购买VIP';
      case 3:
        return '购买金币';
      case 4:
        return '余额提现';
      case 5:
        return '金币提现';
      case 6:
        return '推广收益';
      case 7:
        return '购买视频';
      case 8:
        return '视频收益';
      case 9:
        return '金币提现失败';
      case 10:
        return '余额提现失败';
      case 11:
        return '后台设置';
      case 12:
        return '购买门票';
      case 13:
        return '活动门票';
      case 14:
        return '楼凤解锁';
      case 15:
        return '楼凤解锁收益';
      case 16:
        return '预约嫩模';
      case 17:
        return '预约嫩模收益';
      case 18:
        return '活动消费';
      case 19:
        return '系统赠送';
      case 20:
        return '预约订单取消-退金币';
      default:
        return '未知类型'; // 如果tranType不在已定义的范围内
    }
  }
}
